
#include "../gdal/include/gdal_priv.h"
#include "../gdal/include/ogrsf_frmts.h"
#include <iostream>
#pragma comment(lib, "gdal_i.lib")
using namespace std;

int main(int argc, char* argv[])
{
	if(argc!=2)
    {
        return 0;
    }
	OGRRegisterAll();
    GDALDataset *poDataset;
    GDALAllRegister();
	cout<<argv[0]<<endl;
    poDataset = (GDALDataset *) GDALOpen( argv[1], GA_ReadOnly );
    if( poDataset != NULL )
    {
        cout<<"RasterXSize:"<<poDataset->GetRasterXSize()<<endl;
        cout<<"RasterYSize:"<<poDataset->GetRasterYSize()<<endl;
        cout<<"RasterCount:"<<poDataset->GetRasterCount()<<endl;
		//cout<<poDataset->GetRasterBand()<<endl;
    }

	int a ;
	cin>>a;

	OGRDataSource *poDS = NULL;
    poDS = OGRSFDriverRegistrar::Open("C:\\data\\house.shp", FALSE );
    if( poDS == NULL )
    {
        printf( "Open failed.\n" );
        exit( 1 );
    }

    OGRLayer  *poLayer;

    poLayer = poDS->GetLayerByName("house");

    OGRFeature *poFeature;

    poLayer->ResetReading();
    while( (poFeature = poLayer->GetNextFeature()) != NULL )
    {
        OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
        int iField;

        for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
        {
            OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );

            if( poFieldDefn->GetType() == OFTInteger )
                printf( "%d,", poFeature->GetFieldAsInteger( iField ) );
            else if( poFieldDefn->GetType() == OFTReal )
                printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
            else if( poFieldDefn->GetType() == OFTString )
                printf( "%s,", poFeature->GetFieldAsString(iField) );
            else
                printf( "%s,", poFeature->GetFieldAsString(iField) );
        }

        OGRGeometry *poGeometry;

        poGeometry = poFeature->GetGeometryRef();
        if( poGeometry != NULL 
            && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
        {
            OGRPoint *poPoint = (OGRPoint *) poGeometry;

            printf( "%.3f,%3.f\n", poPoint->getX(), poPoint->getY() );
        }
        else
        {
            printf( "no point geometry\n" );
        }       
        OGRFeature::DestroyFeature( poFeature );
    }

    OGRDataSource::DestroyDataSource( poDS );

    return 0;
	
}
